<template>
	<view class="container">
		<view v-for="(item, id) in leaveList" :key="item.id" class="leave-item">
			<view class="leave-info" @click="toleaveDetail(item.id)">
				<!-- <view class="info-item">用户名id：{{ item.usersNickNameId }}</view> -->
				<u-avatar :src="'https://www.gzzyue.com/prod-api'+item.imgavater" size="60"></u-avatar>
				<view class="info-item">班级：{{ item.classs }}</view>
				<view class="info-item">请假开始时间：{{ item.leaveTimeStart }}</view>
				<view class="info-item">请假结束时间：{{ item.leaveTimeEnd }}</view>
				<view class="info-item" v-html="'请假说明：'+item.leaveDetailes"></view>
				<view class="info-item">老师电话：{{ item.usersNickTelephone }}</view>
				<view class="info-item">学生姓名：{{ item.studentName }}</view>
				<view class="info-item">学生电话：{{ item.studentTelephone }}</view>
				<view class="info-item">发病症状：{{ item.onsetSymptoms }}</view>
				<view class="info-item">诊断疾病：{{ item.diagnose }}</view>
				<view class="info-item">诊断日期：{{ item.diagnosisTime }}</view>
				<view class="info-item">发病日期：{{ item.morbidityTime }}</view>
				<view class="info-item">请假类型：{{ item.leaveType === 1 ? '事假' : '病假' }}</view>
				 <view class="info-item">确认离校人：{{ item.departureConfirmer }}</view>
				<view class="info-item">离校状态：{{ item.state === 1? '未确定离校' : '已确定离校' }}</view>
				<view class="info-item">离校详情：{{ item.departureDetails }}</view>
			</view>
		</view>
		<uni-fab ref="fab" horizontal="right" vertical="bottom" direction="horizontal" @fabClick="toAddAskfor" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				leaveList: []
			};
		},
		mounted() {
			this.fetchLeaveList();
		},
		methods: {
			toAddAskfor() {
				uni.navigateTo({
					url: '/pages/askfor/addaskfor'
				})
			},
			toleaveDetail(id) {
				uni.navigateTo({
					url: '/pages/leave/leaveDetail?id=' + id
				})
			},
			fetchLeaveList() {
				uni.request({
					url: 'https://www.gzzyue.com/prod-api/system/schoolLeavingManagement/list',
					method: 'GET',
					header: {
						'Authorization': uni.getStorageSync("token") //自定义请求头信息
					},
					success: (res) => {
						console.log('res:', res);
						if (res.statusCode == 200) {
							if (res.data.code == 200) {

								this.leaveList = res.data.rows.reverse();

							} else if (res.data.code == 500) {
								uni.$u.toast(res.data.msg)
							} else {
								uni.$u.toast('系统服务异常，请联系管理员！')
							}
						} else {
							uni.$u.toast('系统服务异常，请联系管理员！')
						}
					},
					fail: (errors) => {
						console.log('errors:', errors);
						uni.$u.toast('服务器错误，请联系管理员！')
					},
				});
			},
		}
	};
</script>

<style scoped>
	.container {
		padding: 20rpx;
		background-color: #f2f2f2;
	}


	.leave-item {
		margin-bottom: 20rpx;
		border: none;
		box-shadow: 0 2rpx 5rpx rgba(0, 0, 0, 0.1);
		background-color: #fff;
		border-radius: 5rpx;
		padding: 10rpx;
	}


	.info-item {
		margin-bottom: 8rpx;
	}

	.uni-fab {
		position: fixed;
		right: 20rpx;
		bottom: 20rpx;
	}

	.uni-fab .uni-icons {
		color: #fff;
	}

	.uni-fab {
		background-color: #007aff;
	}
</style>